<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <script>
      //可迭代对象
      var obj = {
        a: 1,
        b: 2,
        [Symbol.iterator]() {
          const keys = Object.keys(this);
          let i = 0;
          return {
            next: () => {
              const propName = keys[i];
              const propValue = this[propName];
              const result = {
                value: {
                  propName,
                  propValue,
                },
                done: i >= keys.length,
              };
              i++;
              return result;
            },
          };
        },
      };

      for (const item of obj) {
        console.log(item); // {propName:"a", propValue:1}
      }
      let s = new Set(obj);
      console.log(s, 'log');
    </script>
  </body>
</html>
